home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / cross / GBDK-2.0.lha / GBDK / examples / irq.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  1KB  |  61 lines

  1. #include <gb.h>
  2. #include <console.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. UBYTE vbl_cnt, tim_cnt;
  7.  
  8. void vbl()
  9. {
  10.   /* Upon IRQ, interrupts are automatically disabled */
  11.   vbl_cnt++;
  12. }
  13.  
  14. void tim()
  15. {
  16.   /* Upon IRQ, interrupts are automatically disabled */
  17.   tim_cnt++;
  18. }
  19.  
  20. void print_counter()
  21. {
  22.   UBYTE cnt;
  23.  
  24.   /* Ensure mutual exclusion (not really necessary in this example)... */
  25.   disable_interrupts();
  26.   cnt = tim_cnt;
  27.   enable_interrupts();
  28.  
  29.   printf(" TIM %u", cnt);
  30.   gotoxy(9, posy());
  31.  
  32.   /* Ensure mutual exclusion (not really necessary in this example)... */
  33.   disable_interrupts();
  34.   cnt = vbl_cnt;
  35.   enable_interrupts();
  36.  
  37.   printf("- VBL %u\n", cnt);
  38. }
  39.  
  40. void main()
  41. {
  42.   /* Ensure mutual exclusion (not really necessary in this example)... */
  43.   disable_interrupts();
  44.   vbl_cnt = tim_cnt = 0;
  45.   add_VBL(vbl);
  46.   add_TIM(tim);
  47.   enable_interrupts();
  48.  
  49.   /* Set TMA to divide clock by 0x100 */
  50.   TMA_REG = 0x00U;
  51.   /* Set clock to 4096 Hertz */
  52.   TAC_REG = 0x04U;
  53.   /* Handle VBL and TIM interrupts */
  54.   set_interrupts(VBL_IFLAG | TIM_IFLAG);
  55.  
  56.   while(1) {
  57.     print_counter();
  58.     delay(1000UL);
  59.   }
  60. }
  61.